package com.financial.sys.controller.user;

import com.financial.common.vo.Result;
import com.financial.model.pojo.TUserInfo;
import com.financial.sys.service.user.TUserInfosService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "用户")
@RestController
@RequestMapping("/user/userinfo")
public class UserController {

    @Autowired
    private TUserInfosService tUserInfoService;

    @ApiOperation("获取前台用户的基本信息")
    @PostMapping("/get/{accountId}")
    public Result selectUserInfo(@PathVariable(name = "accountId", required = false) String accountId){
        System.out.println(accountId+"----");
        TUserInfo tUserInfo=tUserInfoService.selectUserInfo(accountId);
        if(tUserInfo!=null){
            return Result.ok().data(tUserInfo);
        }
        return Result.error().message("用户信息加载失败");

    }

    @ApiOperation("更新用户")
    @PostMapping("/update")
    public Result updateUserInfo(@ApiParam(name = "tUserInfo",value = "用户更新对象")
                                             TUserInfo tUserInfo){
        int i=tUserInfoService.UserInfoUpdate(tUserInfo);
        if(i>0){
            return Result.ok().data();
        }
        return  Result.error().message("修改失败!");
    }


    @ApiOperation ("图片上传")
    @PostMapping ("/uploadAvatar")
    public Result uploadAvatar(MultipartFile file) {
        String upload = tUserInfoService.upload(file);
        return Result.ok().data(upload);
    }
}
